<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <!-- <el-form-item label="公司代码" prop="factoryCode">
         <el-input
           v-model="queryParams.factoryCode"
           placeholder="请输入公司代码"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报工单号" prop="danhao">
        <el-input
          v-model="queryParams.bgdanhao"
          placeholder="请输入报工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="派工单号" prop="danhao">
        <el-input
          v-model="queryParams.danhao"
          placeholder="请输入派工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="订单号" prop="orderNo">
         <el-input
           v-model="queryParams.orderNo"
           placeholder="请输入订单号"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <!--  <el-form-item label="合同号" prop="contractNo">
          <el-input
            v-model="queryParams.contractNo"
            placeholder="请输入合同号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>-->
      <el-form-item label="排产编号" prop="pcCode">
        <el-input
          v-model="queryParams.pcCode"
          placeholder="请输入排产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排产日期" prop="pcDate">
        <el-date-picker clearable
                        v-model="queryParams.pcDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择排产日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产日期" prop="scDate">
        <el-date-picker clearable
                        v-model="queryParams.scDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择生产日期">
        </el-date-picker>
      </el-form-item>
    <!--  <el-form-item label="交货日期" prop="jhDate">
        <el-date-picker clearable
                        v-model="queryParams.jhDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择交货日期">
        </el-date-picker>
      </el-form-item>-->
      <!--      <el-form-item label="生产线代码" prop="lineCode">
              <el-input
                v-model="queryParams.lineCode"
                placeholder="请输入生产线代码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="生产线名称" prop="lineName">
              <el-input
                v-model="queryParams.lineName"
                placeholder="请输入生产线名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>-->
      <el-form-item label="工位代码" prop="gwCode">
        <el-input
          v-model="queryParams.gwCode"
          placeholder="请输入工位代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工位名称" prop="gwName">
        <el-input
          v-model="queryParams.gwName"
          placeholder="请输入工位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
   <!--   <el-form-item label="员工工号" prop="empNum">
        <el-input
          v-model="queryParams.empNum"
          placeholder="请输入员工工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="员工姓名" prop="empName">
        <el-input
          v-model="queryParams.empName"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--     <el-form-item label="工序产品编号" prop="gxProCode">
             <el-input
               v-model="queryParams.gxProCode"
               placeholder="请输入工序产品编号"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
           <el-form-item label="产品名称" prop="proName">
             <el-input
               v-model="queryParams.proName"
               placeholder="请输入产品名称"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
           <el-form-item label="领料物料" prop="dyProCode">
             <el-input
               v-model="queryParams.dyProCode"
               placeholder="请输入领料物料"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>
           <el-form-item label="报工物料" prop="dyYclCode">
             <el-input
               v-model="queryParams.dyYclCode"
               placeholder="请输入报工物料"
               clearable
               @keyup.enter.native="handleQuery"
             />
           </el-form-item>-->
      <!-- <el-form-item label="是否接单0-未接 1-接单" prop="isJd">
         <el-input
           v-model="queryParams.isJd"
           placeholder="请输入是否接单0-未接 1-接单"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <el-form-item label="领料物料" prop="dyYclCode">
        <el-input
          v-model="queryParams.dyYclCode"
          placeholder="请输入领料物料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报工物料" prop="dyProCode">
        <el-input
          v-model="queryParams.dyProCode"
          placeholder="请输入报工物料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料识别码" prop="itemIdentifyCode">
        <el-input
          v-model="queryParams.itemIdentifyCode"
          placeholder="请输入物料识别码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['procontrol:orderInfoBg:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['procontrol:orderInfoBg:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['procontrol:orderInfoBg:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['procontrol:orderInfoBg:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="orderInfoBgList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="订单号" width="130" show-overflow-tooltip align="center" prop="orderNo" />
      <el-table-column label="报工单号" width="130" show-overflow-tooltip align="center" prop="bgdanhao" />
      <el-table-column label="派工单号" width="130" show-overflow-tooltip align="center" prop="danhao" />
      <el-table-column label="排产编号" width="120" show-overflow-tooltip align="center" prop="pcCode" />
      <el-table-column label="排产日期" align="center" prop="pcDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pcDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="员工工号"  width="130" align="center" prop="empNum" />
      <el-table-column label="员工姓名" width="100" align="center" prop="empName" />
      <el-table-column label="排产数量" align="center" prop="pcNum" />
      <el-table-column label="派工数量"  align="center" prop="pgNum" />
      <el-table-column label="报工数量" align="center" prop="bgNum" />
      <el-table-column label="返修数量" align="center" prop="returnNum" />
      <el-table-column label="生产线代码" width="130" align="center" prop="lineCode" />
      <el-table-column label="生产线名称" width="130" show-overflow-tooltip align="center" prop="lineName" />
      <el-table-column label="工位代码" width="130" show-overflow-tooltip align="center" prop="gwCode" />
      <el-table-column label="工位名称" width="130" show-overflow-tooltip align="center" prop="gwName" />
      <el-table-column label="产品类型" align="center" prop="proType" />
      <el-table-column label="工序产品编号" width="130" show-overflow-tooltip align="center" prop="gxProCode" />
      <el-table-column label="领料名称" width="130" show-overflow-tooltip align="center" prop="proName" />
      <el-table-column label="领料物料" width="200" show-overflow-tooltip   align="center" prop="dyYclCode" />
      <el-table-column label="报工物料"  width="200" show-overflow-tooltip align="center" prop="dyProCode" />
      <el-table-column label="物料识别码" width="280" show-overflow-tooltip   align="center" prop="itemIdentifyCode" />
      <el-table-column label="外径公差" width="120" align="center" prop="wjgc" />
      <el-table-column label="内径公差" width="120" align="center" prop="njgc" />
      <el-table-column label="厚度公差" width="120" align="center" prop="hdgc" />
      <el-table-column label="台径*台高" width="120" align="center" prop="tjtg" />
      <el-table-column label="中心距" width="120" align="center" prop="zxj" />
      <el-table-column label="孔径+孔数" width="120" align="center" prop="kjks" />
      <el-table-column label="计算重量" width="120" align="center" prop="jszl" />
      <el-table-column label="下料重量" width="120" align="center" prop="xlzl" />
      <el-table-column label="倒角" align="center" prop="dj" width="120"/>
      <el-table-column label="水线" align="center" prop="sx" width="120"/>
      <el-table-column label="密封面倒角" align="center" prop="mfmdj" width="120"/>
      <el-table-column label="说明" align="center" prop="content"  width="180" show-overflow-tooltip/>
      <el-table-column label="合同号" width="160" show-overflow-tooltip align="center" prop="contractNo" />
      <el-table-column label="生产日期" align="center" prop="scDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="jhDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jhDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" width="160" align="center" prop="createTime" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="更新时间" width="160" align="center" prop="updateTime" />
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" fixed="right" width="160" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-add"
            @click="handleWgOk(scope.row)"
            v-hasPermi="['procontrol:orderInfoBg:wgOk']"
          >确认</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['procontrol:orderInfoBg:edit']"
          >修改</el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             v-hasPermi="['procontrol:orderInfoBg:remove']"
           >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
   <!--产线工位报工单完工确认对话框-->
    <el-dialog :close-on-click-modal="false" :title="wgOk.title" :visible.sync="wgOk.open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input v-model="form.orderNo" placeholder="请输入订单号" />
      </el-form-item>
      <el-form-item label="排产编号" prop="pcCode">
        <el-input v-model="form.pcCode" placeholder="请输入排产编号" />
      </el-form-item>
      <el-form-item label="排产日期" prop="pcDate">
        <el-date-picker clearable
                        v-model="form.pcDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择排产日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产日期" prop="scDate">
        <el-date-picker clearable
                        v-model="form.scDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择生产日期">
        </el-date-picker>
      </el-form-item>
        <el-form-item label="领料物料" prop="dyYclCode">
          <el-input v-model="form.dyYclCode" placeholder="请输入领料物料" />
        </el-form-item>
        <el-form-item label="报工物料" prop="dyProCode">
          <el-input v-model="form.dyProCode" placeholder="请输入报工物料" />
        </el-form-item>
      <el-form-item label="员工工号" prop="empNum">
        <el-input v-model="form.empNum" placeholder="请输入员工工号" />
      </el-form-item>
      <el-form-item label="员工姓名" prop="empName">
        <el-input v-model="form.empName" placeholder="请输入员工姓名" />
      </el-form-item>
      <el-form-item label="排产数量" prop="pcNum">
        <el-input v-model="form.pcNum" placeholder="请输入排产数量" />
      </el-form-item>
      <el-form-item label="派工数量" prop="pgNum">
        <el-input v-model="form.pgNum" placeholder="请输入派工数量" />
      </el-form-item>
      <el-form-item label="报工数量" prop="bgNum">
        <el-input v-model="form.bgNum" placeholder="请输入报工数量" />
      </el-form-item>
      <el-form-item label="返修数量" prop="returnNum">
        <el-input v-model="form.returnNum" placeholder="请输入返修数量" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="wgOk.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改产线工位报工单对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司代码" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="factoryName">
          <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="单号" prop="danhao">
          <el-input v-model="form.danhao" placeholder="请输入单号" />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="合同号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同号" />
        </el-form-item>
        <el-form-item label="排产编号" prop="pcCode">
          <el-input v-model="form.pcCode" placeholder="请输入排产编号" />
        </el-form-item>
        <el-form-item label="排产日期" prop="pcDate">
          <el-date-picker clearable
            v-model="form.pcDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择排产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产日期" prop="scDate">
          <el-date-picker clearable
            v-model="form.scDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货日期" prop="jhDate">
          <el-date-picker clearable
            v-model="form.jhDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交货日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产线代码" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入生产线代码" />
        </el-form-item>
        <el-form-item label="生产线名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入生产线名称" />
        </el-form-item>
        <el-form-item label="工位代码" prop="gwCode">
          <el-input v-model="form.gwCode" placeholder="请输入工位代码" />
        </el-form-item>
        <el-form-item label="工位名称" prop="gwName">
          <el-input v-model="form.gwName" placeholder="请输入工位名称" />
        </el-form-item>
        <el-form-item label="员工工号" prop="empNum">
          <el-input v-model="form.empNum" placeholder="请输入员工工号" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="empName">
          <el-input v-model="form.empName" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="工序产品编号" prop="gxProCode">
          <el-input v-model="form.gxProCode" placeholder="请输入工序产品编号" />
        </el-form-item>
        <el-form-item label="产品名称" prop="proName">
          <el-input v-model="form.proName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="领料物料" prop="dyYclCode">
          <el-input v-model="form.dyYclCode" placeholder="请输入领料物料" />
        </el-form-item>
        <el-form-item label="报工物料" prop="dyProCode">
          <el-input v-model="form.dyProCode" placeholder="请输入报工物料" />
        </el-form-item>
        <el-form-item label="排产数量" prop="pcNum">
          <el-input v-model="form.pcNum" placeholder="请输入排产数量" />
        </el-form-item>
        <el-form-item label="派工数量" prop="pgNum">
          <el-input v-model="form.pgNum" placeholder="请输入派工数量" />
        </el-form-item>
        <el-form-item label="报工数量" prop="bgNum">
          <el-input v-model="form.bgNum" placeholder="请输入报工数量" />
        </el-form-item>
        <el-form-item label="返修数量" prop="returnNum">
          <el-input v-model="form.returnNum" placeholder="请输入返修数量" />
        </el-form-item>
        <el-form-item label="是否接单0-未接 1-接单" prop="isJd">
          <el-input v-model="form.isJd" placeholder="请输入是否接单0-未接 1-接单" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrderInfoBg, getOrderInfoBg, delOrderInfoBg, addOrderInfoBg, updateOrderInfoBg } from "@/api/procontrol/orderInfoBg";

export default {
  name: "OrderInfoBg",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产线工位报工单表格数据
      orderInfoBgList: [],
      wgOk:{
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryCode: null,
        factoryName: null,
        bgdanhao: null,
        danhao: null,
        orderNo: null,
        contractNo: null,
        pcCode: null,
        pcDate: null,
        scDate: null,
        jhDate: null,
        lineCode: null,
        lineName: null,
        gwCode: null,
        gwName: null,
        empNum: null,
        empName: null,
        proType: null,
        gxProCode: null,
        proName: null,
        dyProCode: null,
        dyYclCode: null,
        pcNum: null,
        pgNum: null,
        bgNum: null,
        returnNum: null,
        isJd: null,
        itemIdentifyCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产线工位报工单列表 */
    getList() {
      this.loading = true;
      listOrderInfoBg(this.queryParams).then(response => {
        this.orderInfoBgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        danhao: null,
        orderNo: null,
        contractNo: null,
        pcCode: null,
        pcDate: null,
        scDate: null,
        jhDate: null,
        lineCode: null,
        lineName: null,
        gwCode: null,
        gwName: null,
        empNum: null,
        empName: null,
        proType: null,
        gxProCode: null,
        proName: null,
        dyProCode: null,
        dyYclCode: null,
        pcNum: null,
        pgNum: null,
        bgNum: null,
        returnNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isJd: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产线工位报工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderInfoBg(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产线工位报工单";
      });
    },
    /** 修改按钮操作 */
    handleWgOk(row) {
      this.reset();
      const id = row.id || this.ids
      getOrderInfoBg(id).then(response => {
        this.form = response.data;
        this.wgOk.open = true;
        this.wgOk.title = "产线工位报工单完工确认";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrderInfoBg(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderInfoBg(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除产线工位报工单编号为"' + ids + '"的数据项？').then(function() {
        return delOrderInfoBg(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('procontrol/orderInfoBg/export', {
        ...this.queryParams
      }, `orderInfoBg_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
